package org.wishwork.api.product.category;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import org.wishwork.api.ExtendBase;

import java.util.List;

/**
 * @description:
 * @author: WangYX
 * @create: 2022-04-08 17:11
 * @Version: 1.0.0
 **/
@Getter
@ToString
@EqualsAndHashCode
public class CategoryQueryRequest extends ExtendBase {

    /**
     * 类目id集合
     */
    private List<Integer> cIds;

    /**
     * 父级类目id集合
     */
    private List<Integer> parentCIds;

    private CategoryQueryRequest(Integer pageIndex, Integer pageSize, String modifiedBegin, String modifiedEnd,
                                 List<Integer> cIds, List<Integer> parentCIds) {
        super(pageIndex, pageSize, modifiedBegin, modifiedEnd);
        this.cIds = cIds;
        this.parentCIds = parentCIds;
    }

    @Override
    public Builder toBuilder() {
        return new Builder().pageIndex(this.pageIndex)
                .pageSize(this.pageSize)
                .modifiedBegin(this.modifiedBegin)
                .modifiedEnd(this.modifiedEnd)
                .cIds(this.cIds)
                .parentCIds(this.parentCIds);
    }

    public static Builder builder() {
        return new Builder();
    }

    public static class Builder extends ExtendBase.Builder<Builder, CategoryQueryRequest> {
        private List<Integer> cIds;
        private List<Integer> parentCIds;

        @Override
        public Builder modifiedBegin(String modifiedBegin) {
            this.modifiedBegin = modifiedBegin;
            return this;
        }

        @Override
        public Builder modifiedEnd(String modifiedEnd) {
            this.modifiedEnd = modifiedEnd;
            return this;
        }

        @Override
        public Builder pageIndex(Integer pageIndex) {
            this.pageIndex = pageIndex;
            return this;
        }

        @Override
        public Builder pageSize(Integer pageSize) {
            this.pageSize = pageSize;
            return this;
        }

        public Builder cIds(List<Integer> cIds) {
            this.cIds = cIds;
            return this;
        }

        public Builder parentCIds(List<Integer> parentCIds) {
            this.parentCIds = parentCIds;
            return this;
        }

        @Override
        public CategoryQueryRequest build() {
            this.pageIndex = this.pageIndex == null ? 1 : this.pageIndex < 0 ? 1 : this.pageIndex;
            this.pageSize = this.pageSize == null ? 30 : this.pageSize < 0 ? 30 : this.pageSize;
            return new CategoryQueryRequest(this.pageIndex, this.pageSize, this.modifiedBegin, this.modifiedEnd, this.cIds, this.parentCIds);
        }
    }


}
